<?php

class AdminModules extends Modules {
    const table_member = 'mc_members';
    const table_member_permission = 'mc_member_permission';
    const table_product_category = 'mc_product_category';
    const table_specs = 'mc_specs';
    const table_product = 'mc_product';
    const table_product_specs = 'mc_product_specs';
    const table_news = 'mc_news';
    const table_news_category = 'mc_news_category';
    const table_product_maker = 'mc_product_maker';
    const table_product_maker_category = 'mc_product_maker_category';
    const table_product_order = 'mc_product_order';
    const table_product_customer_order = 'mc_product_customer_order';
    const table_product_order_detail = 'mc_product_order_detail';
    const table_slider = 'mc_slider';
    const table_manage_common = 'mc_manage_common';
    const table_customer_link = 'mc_mct_customer_link';
    const table_customer = 'mc_custommer_info';
    const table_customer_product = 'mc_customer_product';
    const table_customer_statistics = "mc_customer_statistics";
    const table_product_image = 'mc_product_image';
    const table_support_online = 'mc_support_online';
    const table_customer_contact = 'mc_customer_contact';
    const table_company_common = 'mc_company_common';
    const table_user_online = 'mc_user_online';
    const table_visited = 'mc_visited';

    //not change
    function __construct($aryConfig) {
        $this->setConfig($aryConfig);
    }

    public function selectLoginInfo($loginData, &$result) {
        try {
            $result = array();
            $sql = "SELECT  member_id,
                        member_login_name,
                        member_full_name,
                        member_is_master
                FROM " . self::table_member . "
                WHERE member_login_name = ?
                AND member_password = ? ";
            $aryBin = array();
            $aryBin[] = $loginData['member_login_name'];
            $aryBin[] = md5(md5($loginData['member_login_password']));
            $intOk = $this->getArray($sql, $result, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function selectLoginInfoByUser($aryCondition, &$aryData) {
        try {
            $result = array();
            $sql = "SELECT  member_id,
                        member_login_name,
                        member_full_name,
                        member_is_master
                FROM " . self::table_member . "
                WHERE member_id = ? ";
            $aryBin = array();
            $aryBin[] = $aryCondition['member_id'];
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategory(&$aryCategory) {
        try {
            $sql = "SELECT  category_id,
                        category_name,
                        category_parent,
                        category_level,
                        category_total_child
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?
                    ORDER BY category_order ASC ";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryId(&$aryCategory, $parent = null) {
        try {
            $sql = "SELECT  category_id
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($parent)) {
                $sql.=" AND category_parent = ?";
                $aryBin[] = $parent;
            }
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryParentPath($categoryId) {
        try {
            $sql = "SELECT category_parent FROM " . self::table_product_category . "
                WHERE category_del_flag = ? AND category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $aryResultData = array();
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $aryCategoryId = array();
            if ($aryResultData[0]['category_parent'] != 0) {
                $aryCategoryId[] = $aryResultData[0]['category_parent'];
                $aryCategoryId = array_merge($this->getCategoryParentPath($aryResultData[0]['category_parent']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCatParentPath($newsCategoryId) {
        try {
            $sql = "SELECT news_category_parent FROM " . self::table_news_category . "
                WHERE news_category_del_flag = ? AND news_category_id = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsCategoryId;
            $aryResultData = array();
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $aryCategoryId = array();
            if ($aryResultData[0]['news_category_parent'] != 0) {
                $aryCategoryId[] = $aryResultData[0]['news_category_parent'];
                $aryCategoryId = array_merge($this->getNewsCatParentPath($aryResultData[0]['news_category_parent']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSecsParentPath($specsId) {
        try {
            $sql = "SELECT specs_parent FROM " . self::table_specs . "
                WHERE specs_del_flag = ? AND specs_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $specsId;
            $aryResultData = array();
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $arySpecsId = array();
            if ($aryResultData[0]['specs_parent'] != 0) {
                $arySpecsId[] = $aryResultData[0]['specs_parent'];
                $arySpecsId = array_merge($this->getSecsParentPath($aryResultData[0]['specs_parent']), $arySpecsId);
            }
            return $arySpecsId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsNameById($specsId) {
        try {
            $sql = "SELECT specs_name FROM " . self::table_specs . "
                    WHERE specs_del_flag = ? AND specs_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $specsId;
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            return $aryResultData[0]['specs_name'];
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveProductSpecs($aryProductSpecs) {
        try {
            $intOk = $this->insert(self::table_product_specs, $aryProductSpecs);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryChildPath($categoryId) {
        try {
            $sql = "SELECT category_id
                    FROM " . self::table_product_category . "
                WHERE category_del_flag = ? AND category_parent = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;

            $aryResultData = array();

            $intOk = $this->getArray($sql, $aryResultData, $aryBin);

            $aryCategoryId = array();

            foreach ($aryResultData as $key => $value) {

                $aryCategoryId[] = $value['category_id'];

                $aryCategoryId = array_merge($this->getCategoryChildPath($value['category_id']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategory(&$aryCategory, $categoryId = null) {
        try {
            $sql = "SELECT  news_category_id,
                        news_category_name,
                        news_category_level,
                        news_category_parent,
                        news_category_filter,
                        news_category_total_child,
                        news_category_product_category
                    FROM " . self::table_news_category . "
                    WHERE news_category_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($categoryId)) {
                $sql.=" AND news_category_parent = ?";
                $aryBin[] = $categoryId;
            }
            $sql.=" ORDER BY news_category_order ASC";

            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategoryById($categoryId, &$aryResultData) {
        try {
            $sql = "SELECT  news_category_id,
                        news_category_name,
                        news_category_title,
                        news_category_keywords,
                        news_category_description,
                        news_category_product_category
                    FROM " . self::table_news_category . "
                    WHERE news_category_del_flag = ? ";
            $sql.=" AND news_category_id = ? ";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;

            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertCategory($aryInsertCategorys, &$lastCategoryId) {
        try {
            $intOk = $this->insert(self::table_product_category, $aryInsertCategorys);
            $lastCategoryId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductMaker($aryProductMakerInsert, &$productMakerId) {
        try {
            $intOk = $this->insert(self::table_product_maker, $aryProductMakerInsert);
            $productMakerId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductMakerCategory($aryProductMakerCategory) {
        try {
            $intOk = $this->insert(self::table_product_maker_category, $aryProductMakerCategory);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductMaker($aryCondition, $aryProductMakerUpdate) {
        try {
            $intOk = $this->update(self::table_product_maker, $aryProductMakerUpdate, $aryCondition);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductMakerCategory($aryCondition2, $aryMakerCategoryUpdate) {
        try {
            $intOk = $this->update(self::table_product_maker_category, $aryMakerCategoryUpdate, $aryCondition2);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertNewsCategory($aryNewsCategory, &$lastId) {
        try {
            $intOk = $this->insert(self::table_news_category, $aryNewsCategory);
            $lastId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryById($categoryId, &$aryCategory) {
        try {
            $sql = "SELECT category_id,
                        category_parent,
                        category_name,
                        category_total_child
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryImageByListId($listChildId, &$aryCategoryImage) {
        try {
            $sql = "SELECT category_id,
                        category_name_filter,
                        category_main_image,
                        category_small_image,
                        category_large_image
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_id IN($listChildId)";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryCategoryImage, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSubCatByCatId($categoryId, &$aryCategory) {
        try {
            $sql = "SELECT category_id,
                        category_name,
                        category_total_child
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_parent = ?
                ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkLevelCategory($categoryId, &$aryCategory) {
        try {
            $sql = "SELECT category_level
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getTotalChildOfParentCategory($categoryId, &$aryData) {
        try {
            $sql = "SELECT category_total_child FROM " . self::table_product_category . "
            WHERE category_id = ?";
            $aryBin = array();
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateCatNumOfChild($parentCategoryId, $totalChild) {
        try {
            $sql = "UPDATE " . self::table_product_category . "
                    SET category_total_child = category_total_child + $totalChild
                    WHERE category_id = ?";
            $aryBin = array();
            $aryBin[] = $parentCategoryId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateTotalChildNewsCat($newsCategoryId, $totalNewsChild) {
        try {
            $sql = "UPDATE " . self::table_news_category . "
                    SET news_category_total_child = news_category_total_child + $totalNewsChild
                    WHERE news_category_id = ?";
            $aryBin = array();
            $aryBin[] = $newsCategoryId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteTotalChildOfParent($parentCategoryId) {
        try {
            $sql = "UPDATE " . self::table_product_category . "
                    SET category_total_child = category_total_child - 1
                    WHERE category_id = ?";
            $aryBin = array();
            $aryBin[] = $parentCategoryId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteTotalChildOfNewsParent($parentId) {
        try {
            $sql = "UPDATE " . self::table_news_category . "
                    SET news_category_total_child = news_category_total_child - 1
                    WHERE news_category_id = ?";
            $aryBin = array();
            $aryBin[] = $parentId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function editCatById($aryCatEdit, $config) {
        try {
            $intOk = $this->update(self::table_product_category, $aryCatEdit, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function editNewsCatById($aryCatEdit, $config) {
        try {
            $intOk = $this->update(self::table_news_category, $aryCatEdit, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getRootCategoryId($parentId) {
        try {
            $sql = "SELECT category_parent
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $parentId;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $aryCategory[0]['category_parent'];
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteProductSpecsByProcutId($productId) {
        try {
            $sql = "DELETE FROM " . self::table_product_specs . "
                WHERE product_specs_product_id = ?";
            $aryBin = array();
            $aryBin[] = $productId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteCategoryById($aryUpdate, $config) {
        try {
            $intOk = $this->update(self::table_product_category, $aryUpdate, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteNewCategoryById($aryUpdate, $config) {
        try {
            $intOk = $this->update(self::table_news_category, $aryUpdate, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteNewsByNewsCategoryId($aryUpdate, $config) {
        try {
            $intOk = $this->update(self::table_news, $aryUpdate, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveProductData($aryProductData, &$productId) {
        try {
            $intOk = $this->insert(self::table_product, $aryProductData);
            $productId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveProductCategory($aryProductCategory) {
        try {
            $intOk = $this->insert(self::table_product_specs, $aryProductCategory);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductCategory($aryUpdateProductCategory, $aryUpdateConditions) {
        try {
            $intOk = $this->update(self::table_product_specs, $aryUpdateProductCategory, $aryUpdateConditions);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProduct($aryConditions, $listCategoryId, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_maker_name,
                        product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_creator_name,
                        product_created_date,
                        product_updater_name,
                        product_updated_date,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_price_vnd_km,
                        product_price_active_km,
                        product_transportation_name,
                        product_is_vat
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;

            $sql.="AND product_category_id IN($listCategoryId)";

            if (isset($aryConditions['product_maker_id']) && $aryConditions['product_maker_id'] != 0) {
                $productMakerId = $aryConditions['product_maker_id'];
                $sql.=" AND product_maker_id = ?";
                $aryBin[] = $productMakerId;
            }

            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            } else {
                $sql.=" ORDER BY product_updated_date DESC";
            }
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductTotalPage($aryConditions, $listCategoryId, &$aryProduct) {
        try {
            $sql = "SELECT product_id
                FROM " . self::table_product . "
                    WHERE product_del_flag = 0 ";

            $sql.="AND product_category_id IN($listCategoryId)";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProduct);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductMaker(&$aryProductMaker) {
        try {
            $sql = "SELECT product_maker_id,
                        product_maker_name,
                        product_maker_main_logo,
                        product_maker_small_logo
                FROM " . self::table_product_maker . "
                    WHERE product_maker_del_flag = ?
                    ORDER BY product_maker_name ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductMakerForAddProduct(&$aryProductMaker) {
        try {
            $sql = "SELECT product_maker_id,
                        product_maker_name,
                        product_maker_category_category_id
                FROM " . self::table_product_maker . "
                INNER JOIN " . self::table_product_maker_category . "
                ON product_maker_id = product_maker_category_maker_id
                    WHERE product_maker_del_flag = ?
                    ORDER BY product_maker_name ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductMakerByCatId($categoryId, &$aryProductMaker) {
        try {
            $sql = "SELECT product_maker_category_maker_id
                FROM " . self::table_product_maker_category . "
                WHERE product_maker_category_del_flag = ? AND product_maker_category_category_id = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryProductMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListProductMakerData($aryConditions, $listCategoryId, &$aryProductMaker) {
        try {
            $sql = "SELECT product_maker_category_id,
                        product_maker_category_maker_id,
                        product_maker_category_category_id,
                        product_maker_name,
                        product_maker_main_logo,
                        category_name
                FROM " . self::table_product_maker_category . "
                INNER JOIN " . self::table_product_maker . "
                ON product_maker_category_maker_id = product_maker_id
                INNER JOIN " . self::table_product_category . "
                ON product_maker_category_category_id = category_id
                WHERE product_maker_category_del_flag = 0 AND product_maker_category_category_id IN ($listCategoryId)";

            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            }
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProductMaker);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductMakerDataById($productMakerId, &$aryProductMaker) {

        try {
            $sql = "SELECT product_maker_id,
                        product_maker_name
                FROM " . self::table_product_maker . "
                WHERE product_maker_del_flag = ? AND product_maker_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productMakerId;
            $intOk = $this->getArray($sql, $aryProductMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNews($aryConditions, &$aryNewsData) {
        try {
            $sql = "SELECT news_id,
                        news_new_category_id,
                        news_title_filter,
                        news_title,
                        news_content_filter,
                        news_main_image,
                        news_creator_name,
                        news_created_date,
                        news_updater_name,
                        news_updated_date
                FROM " . self::table_news . "
                    WHERE news_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($aryConditions['news_list_category_id'])) {
                $listCategoryId = $aryConditions['news_list_category_id'];
                $sql.=" AND news_new_category_id IN($listCategoryId)";
            }
            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductById($productId, &$aryData) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_content,
                        product_title_filter,
                        product_search_title,
                        product_search_keyword,
                        product_search_description,
                        product_category_id,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_highlight,
                        product_type_id
                FROM " . self::table_product . "
                    WHERE product_del_flag = ?
                    AND product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductByListId($strProductId, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_main_image,
                        product_price_vnd,
                        product_price_vnd_in,
                        product_category_id,
                        product_category_name
                FROM " . self::table_product . "
                    WHERE product_del_flag = ?
                    AND product_id IN($strProductId)";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsByProductId($productId, &$aryProductSpecs) {
        try {
            $sql = "SELECT  product_specs_specs_id,
                        product_specs_specs_name
                FROM " . self::table_product_specs . "
                WHERE product_specs_product_id = ?
                AND product_specs_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $productId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductSpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProduct($aryInsert, $aryCondition) {
        try {
            $intOk = $this->update(self::table_product, $aryInsert, $aryCondition);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveNewsData($aryNewsInsert) {
        try {
            $intOk = $this->insert(self::table_news, $aryNewsInsert);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsById($newId, &$aryData) {
        try {
            $sql = "SELECT news_id,
                        news_new_category_id,
                        news_title,
                        news_content,
                        news_main_image,
                        news_type
                FROM " . self::table_news . "
                    WHERE news_del_flag = ?
                    AND news_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsImagesById($newsId, &$aryData) {
        try {
            $sql = "SELECT news_id,
                        news_main_image,
                        news_large_image
                FROM " . self::table_news . "
                    WHERE news_del_flag = ?
                    AND news_id = ?";
            $aryBin = array();
            $aryBin[] = 1;
            $aryBin[] = $newsId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsImagesByCategoryId($newsCategoryId, &$aryData) {
        try {
            $sql = "SELECT news_id,
                        news_main_image,
                        news_large_image
                FROM " . self::table_news . "
                    WHERE news_del_flag = ?
                    AND news_new_category_id = ?";
            $aryBin = array();
            $aryBin[] = 1;
            $aryBin[] = $newsCategoryId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateNewsData($aryNewsInsert, $aryCondition) {
        try {
            $intOk = $this->update(self::table_news, $aryNewsInsert, $aryCondition);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkExistedMember($loginName) {
        try {
            $sql = "SELECT member_login_name FROM " . self::table_member . "
                    WHERE member_login_name = ?";
            $aryBin = array();
            $aryBin[] = $loginName;
            $intOk = $this->getArray($sql, $existed, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertMemember($aryInsertMember, &$memberId) {
        try {
            $intOk = $this->insert(self::table_member, $aryInsertMember);
            $memberId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateMember($aryInsertMember, $config) {
        try {
            $intOk = $this->update(self::table_member, $aryInsertMember, $config);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertMemberPermisson($aryInsertPermission) {
        try {
            $intOk = $this->insert(self::table_member_permission, $aryInsertPermission);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteMemberPermission($memberId) {
        try {
            $sql = "DELETE FROM " . self::table_member_permission . "
                    WHERE member_permission_member_id = ?";
            $aryBin = array();
            $aryBin[] = $memberId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListMember($aryConditions, &$aryMember) {
        try {
            $sql = "SELECT member_id,
                        member_login_name,
                        member_full_name,
                        member_phone_number,
                        member_mail
                FROM " . self::table_member . "
                    WHERE member_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryMember, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getMemmberById($memberId, &$aryMember) {
        try {
            $sql = "SELECT member_id,
                        member_login_name,
                        member_full_name,
                        member_phone_number,
                        member_mail,
                        member_yahoo,
                        member_yahoo_pass,
                        member_skype,
                        member_address,
                        member_is_kd
                FROM " . self::table_member . "
                    WHERE member_del_flag = ?
                    AND member_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $memberId;
            $intOk = $this->getArray($sql, $aryMember, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getMemberPermission(&$aryPermission) {
        try {
            $sql = "SELECT member_permission_id,
                        member_permission_member_id,
                        member_permission_module,
                        member_permission,
                        member_permission_module_name,
                        member_permission_name
                FROM " . self::table_member_permission . "
                    WHERE member_permission_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryPermission, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getPermissionByMemberId($memberId, &$aryMemberPermission) {
        try {
            $sql = "SELECT member_permission_module,
                        member_permission
                FROM " . self::table_member_permission . "
                    WHERE member_permission_del_flag = ?
                    AND member_permission_member_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $memberId;
            $intOk = $this->getArray($sql, $aryMemberPermission, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsByCategoryId($categoryId, $specsParent, &$arySpecs) {
        try {
            $sql = "SELECT specs_id,
                        specs_category_id,
                        specs_parent,
                        specs_input_type,
                        specs_level,
                        specs_name,
                        specs_total_child
                FROM " . self::table_specs . "
                WHERE specs_del_flag = ?
                AND specs_category_id = ?
                AND specs_parent = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $aryBin[] = $specsParent;
            $intOk = $this->getArray($sql, $arySpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function selectSpecsByCategoryId($categoryId, &$arySpecs) {
        try {
            $sql = "SELECT specs_id,
                        specs_input_type,
                        specs_level,
                        specs_parent,
                        specs_name
                FROM " . self::table_specs . "
                WHERE specs_del_flag = ?
                AND specs_category_id = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $arySpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSubSpecsBySpecsId($spectId, &$arySpecs) {
        try {
            $sql = "SELECT specs_id,
                        specs_category_id,
                        specs_parent,
                        specs_level,
                        specs_name,
                        specs_input_type,
                        specs_total_child
                FROM " . self::table_specs . "
                WHERE specs_del_flag = ?
                AND specs_parent = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $spectId;
            $intOk = $this->getArray($sql, $arySpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsById($spectId, &$arySpecs) {
        try {
            $sql = "SELECT specs_input_type
                FROM " . self::table_specs . "
                WHERE specs_del_flag = ?
                AND specs_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $spectId;
            $intOk = $this->getArray($sql, $arySpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertSpecs($arySpecs) {
        try {
            $intOk = $this->insert(self::table_specs, $arySpecs);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateSpecsNumOfChild($parentSpectId, $totalChild) {
        try {
            $sql = "UPDATE " . self::table_specs . "
                    SET specs_total_child = specs_total_child + $totalChild
                WHERE specs_id = ?";
            $aryBin = array();
            $aryBin[] = $parentSpectId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteProductByProductId($aryDelete, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product, $aryDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteProductByCatId($aryProductUpdate, $aryProductConditions) {
        try {
            $intOk = $this->update(self::table_product, $aryProductUpdate, $aryProductConditions);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateOrderProductCategory($aryUpdate, $aryConditions) {
        try {
            $intOk = $this->update(self::table_product_category, $aryUpdate, $aryConditions);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateOrderNewsCategory($aryUpdate, $aryConditions) {
        try {
            $intOk = $this->update(self::table_news_category, $aryUpdate, $aryConditions);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductOrderDetail($aryConditions, &$aryOrderDetail) {
        try {
            $sql = "SELECT order_detail_id,
                        order_detail_full_name,
                        order_detail_address,
                        order_detail_phone_number,
                        order_detail_email,
                        order_detail_address_delivery,
                        order_detail_method_delivery,
                        order_detail_delivery_name,
                        order_detail_method_payment,
                        order_detail_payment_name,
                        order_detail_active,
                        order_detail_created_date,
                        order_detail_company_name,
                        order_detail_company_address,
                        order_detail_company_tax_code,
                        order_detail_is_process
                FROM " . self::table_product_order_detail . "
                WHERE order_detail_del_flag = ? AND order_detail_active = ? ";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;

            if (isset($aryConditions['type']) && $aryConditions['type'] == 'new') {
                $sql.=" AND order_detail_is_process = ?";
                $aryBin[] = 0;
            }
            if (isset($aryConditions['type']) && $aryConditions['type'] == 'isProcess') {
                $sql.=" AND order_detail_is_process = ?";
                $aryBin[] = 1;
            }
            if (isset($aryConditions['type']) && $aryConditions['type'] == 'isWait') {
                $sql.=" AND order_detail_is_process = ?";
                $aryBin[] = 2;
            }

            $orderBy = $aryConditions['order_by'];

            $sql.=" ORDER BY order_detail_created_date $orderBy";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryOrderDetail, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductOrderByDetailId($strDetailId, &$aryProductOrder) {
        try {
            $sql = "SELECT product_order_id,
                        product_order_detail_id,
                        product_order_product_id,
                        product_order_product_name,
                        product_order_product_name_filter,
                        product_order_total_product,
                        product_order_product_unit,
                        product_order_product_price,
                        product_order_product_price_in,
                        product_order_total_price,
                        product_order_active,
                        product_order_product_unit,
                        product_order_product_image,
                        product_order_category_id,
                        product_order_category_name,
                        product_order_category_filter,
                        product_order_process_date
                FROM " . self::table_product_order . "
                WHERE product_order_detail_id IN($strDetailId)
                AND product_order_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductOrder, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductOrderData(&$aryProductOrder) {
        try {
            $sql = "SELECT product_order_id,
                        product_order_detail_id,
                        product_order_product_id,
                        product_order_product_name,
                        product_order_total_product,
                        product_order_product_price,
                        product_order_product_price_in,
                        product_order_total_price,
                        product_order_active,
                        product_order_product_image,
                        product_order_category_id,
                        product_order_category_name,
                        product_order_category_filter,
                        product_order_process_date
                FROM " . self::table_product_order . "
                WHERE product_order_del_flag = ? AND product_order_active = ?
                ORDER BY product_order_id ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            $intOk = $this->getArray($sql, $aryProductOrder, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerOrderData(&$aryCustomer) {
        try {
            $sql = "SELECT order_detail_id,
                        order_detail_full_name,
                        order_detail_address,
                        order_detail_phone_number,
                        order_detail_email,
                        order_detail_address_delivery,
                        order_detail_method_delivery,
                        order_detail_delivery_name,
                        order_detail_method_payment,
                        order_detail_payment_name,
                        order_detail_active,
                        order_detail_created_date,
                        order_detail_company_name,
                        order_detail_company_address,
                        order_detail_company_tax_code,
                        order_detail_is_process
                FROM " . self::table_product_order_detail . "
                WHERE order_detail_del_flag = ? AND order_detail_active = ?
                ORDER BY order_detail_id ASC";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            $intOk = $this->getArray($sql, $aryCustomer, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getOrderDetailById($detailId, &$aryOrderDetail) {
        try {
            $sql = "SELECT order_detail_id,
                        order_detail_full_name,
                        order_detail_address,
                        order_detail_phone_number,
                        order_detail_email,
                        order_detail_address_delivery,
                        order_detail_method_delivery,
                        order_detail_delivery_name,
                        order_detail_method_payment,
                        order_detail_payment_name,
                        order_detail_active,
                        order_detail_yahoo,
                        order_detail_created_date,
                        order_detail_company_name,
                        order_detail_company_address,
                        order_detail_company_tax_code,
                        order_detail_comment,
                        order_detail_last_upate_date,
                        order_detail_is_process,
                        order_detail_process_date
                FROM " . self::table_product_order_detail . "
                WHERE order_detail_del_flag = ? AND  order_detail_id = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $detailId;
            $intOk = $this->getArray($sql, $aryOrderDetail, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchCustomerProductOrder($arySearch, &$aryCustomer) {
        try {
            $sql = "SELECT product_customer_id,
                       product_customer_name,
                       product_customer_email,
                       product_customer_mobile,
                       product_customer_address
                FROM " . self::table_product_customer_order . "
                WHERE mc_product_customer_del_flag = ?
                AND (product_customer_search_name LIKE ? OR product_customer_email LIKE ?
                        OR product_customer_mobile LIKE ?)";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = '%' . $arySearch['product_customer_search_name'] . '%';
            $aryBin[] = '%' . $arySearch['product_customer_email'] . '%';
            $aryBin[] = '%' . $arySearch['product_customer_mobile'] . '%';
            $intOk = $this->getArray($sql, $aryCustomer, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateStatusOrder($aryOrderUpdate, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order_detail, $aryOrderUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteOrderById($aryDelete, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order_detail, $aryDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteProductOrderByOrderId($aryDeleteProductOrder, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order, $aryDeleteProductOrder, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchProductData($aryConditions, $listCatId, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_maker_name,
                        product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_creator_name,
                        product_created_date,
                        product_updater_name,
                        product_updated_date,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_price_vnd_km,
                        product_price_active_km,
                        product_transportation_name,
                        product_is_vat,
                        product_creator_name,
                        product_updater_name,
                        product_created_date,
                        product_updated_date
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";

            $sql.=" AND product_title_search LIKE ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = "%" . $aryConditions['product_name'] . "%";

            if ($listCatId != '') {
                $sql.=" AND product_category_id IN($listCatId)";
            }

            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            } else {
                $sql.=" ORDER BY product_updated_date DESC";
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchNewsData($aryConditions, &$aryResult) {
        try {
            $sql = "SELECT news_id,
                        news_new_category_id,
                        news_title_filter,
                        news_title,
                        news_content_filter,
                        news_main_image,
                        news_creator_name,
                        news_created_date,
                        news_updater_name,
                        news_updated_date
                FROM " . self::table_news . "
                    WHERE news_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if($aryConditions['news_title_search'] != ''){
                $sql.=" AND news_title_search LIKE ?";
                $aryBin[] = "%" . $aryConditions['news_title_search'] . "%";
            }
            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {
                $field = $aryConditions['field'];
                $orderType = $aryConditions['order'];
                $sql.=" ORDER BY $field $orderType";
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryResult, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchProductExist($productEncodeName, &$aryCheckResult, $productId = null) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_search
                FROM " . self::table_product . "
                WHERE product_del_flag = ?";

            $aryBin = array();

            $aryBin[] = 0;

            if (isset($productId) && is_numeric($productId)) {

                $sql.=" AND product_id != ?";

                $aryBin[] = $productId;
            }

            $sql.=" AND product_title_search = ?";

            $aryBin[] = $productEncodeName;

            $intOk = $this->getArray($sql, $aryCheckResult, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertSlider($arySlider) {
        try {
            $intOk = $this->insert(self::table_slider, $arySlider);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSlider($aryConditions, &$aryData) {
        try {
            $sql = "SELECT slider_id,
                        slider_title,
                        slider_link,
                        slider_image
                FROM " . self::table_slider;

            $aryBin = array();

            if (isset($aryConditions['slider_type']) && $aryConditions['slider_type'] == 'active') {
                $sql.=" WHERE slider_del_flag = ?";
                $aryBin[] = 0;
            }
            if (isset($aryConditions['slider_type']) && $aryConditions['slider_type'] == 'delete') {
                $sql.=" WHERE slider_del_flag = ?";
                $aryBin[] = 1;
            }
            $sql.=" ORDER BY slider_id DESC";
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSliderById($sliderId, &$arySlider) {
        try {
            $sql = "SELECT slider_id,
                        slider_title,
                        slider_link,
                        slider_image
                FROM " . self::table_slider . "
                WHERE slider_del_flag = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $arySlider, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateSlider($aryUpdateSlider, $aryConfig) {
        try {
            $intOk = $this->update(self::table_slider, $aryUpdateSlider, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteSlider($aryDelete, $aryConfig) {
        try {
            $intOk = $this->update(self::table_slider, $aryDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updatePNewsProductCategory($aryUpdate, $aryConfig) {
        try {
            $intOk = $this->update(self::table_news_category, $aryUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCommonData(&$aryCommonData) {
        try {
            $sql = "SELECT common_currency,
                        common_gioi_thieu,
                        common_huong_dan_mua_hang,
                        common_chinh_sach_bao_hanh
                FROM " . self::table_manage_common;
            $intOk = $this->getArray($sql, $aryCommonData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateCurrentcy($aryCurrency) {
        try {
            $sql = "UPDATE " . self::table_manage_common . "
                    SET common_currency = ?";
            $aryBin = array();
            $aryBin[] = $aryCurrency['common_currency'];
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductImage($aryProductImage) {
        try {
            $intOk = $this->insert(self::table_product_image, $aryProductImage);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductPrice(&$aryProductPrice) {
        try {
            $sql = "SELECT product_id,
                        product_price_vnd
                FROM " . self::table_product . "
                ORDER BY product_id ASC";
            $intOk = $this->getArray($sql, $aryProductPrice);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductUsdPrice(&$aryProductUsdPrice) {
        try {
            $sql = "SELECT product_id,
                        product_price_usd
                FROM " . self::table_product . "
                WHERE product_del_flag = ?
                ORDER BY product_id ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductUsdPrice, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductPrice($aryPriceUpdate, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product, $aryPriceUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteNewsById($aryNewsDelete, $aryConfig) {
        try {
            $intOk = $this->update(self::table_news, $aryNewsDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCurrency(&$aryData) {
        try {
            $sql = "SELECT common_currency FROM " . self::table_manage_common;
            $intOk = $this->getArray($sql, $aryData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustommerProductLink($status, &$aryData) {
        try {
            $sql = "SELECT mct_customer_link_id,
                        mct_customer_link_link,
                        mct_customer_link_customer_id,
                        mct_customer_link_product_id,
                        mct_customer_link_send_date,
                        mct_customer_status,
                        mct_customer_date_process
                FROM " . self::table_customer_link . "
                WHERE mct_customer_link_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            if (is_numeric($status)) {
                $sql.=" AND mct_customer_status = ?";
                $aryBin[] = $status;
            }
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductLinkByCustomerId($aryConditions, &$aryData) {
        try {
            $sql = "SELECT mct_customer_link_id,
                        mct_customer_link_link,
                        mct_customer_link_customer_id,
                        mct_customer_link_product_id,
                        mct_customer_link_send_date,
                        mct_customer_status,
                        mct_customer_date_process
                FROM " . self::table_customer_link . "
                WHERE mct_customer_link_del_flag = ?
                AND mct_customer_link_customer_id = ?
                AND mct_customer_link_product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $aryConditions['mct_customer_link_customer_id'];
            $aryBin[] = $aryConditions['mct_customer_link_product_id'];
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerInfoByListId($strCustomerId, &$aryCustomerInfo) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_address,
                       customer_mobile_phone,
                       customer_home_phone,
                       customer_email,
                       customer_yahoo,
                       customer_skype,
                       customer_date_birthday,
                       customer_join_date,
                       customer_bank_name,
                       customer_bank_number,
                       customer_zone_id,
                       customer_gender
               FROM " . self::table_customer . "
               WHERE customer_del_flag = 0
               AND customer_id IN($strCustomerId)";
            $intOk = $this->getArray($sql, $aryCustomerInfo);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateStatusCustomerLinkData($statusId, $customerId, $productId) {
        try {
            $processDate = date("Y-m-d H:i:s");
            $sql = "UPDATE " . self::table_customer_link . "
                    SET mct_customer_status = $statusId,
                        mct_customer_date_process = ?
                    WHERE mct_customer_link_customer_id = ?
                    AND mct_customer_link_product_id = ?";
            $aryBin = array();
            $aryBin[] = $processDate;
            $aryBin[] = $customerId;
            $aryBin[] = $productId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteMemberById($aryConfig, $aryUpdateMember) {
        try {
            $intOk = $this->update(self::table_member, $aryUpdateMember, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCustomerInfo($aryConditions, &$aryCustomerInfo) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_user_name,
                       customer_email,
                       customer_address,
                       customer_home_phone,
                       customer_mobile_phone,
                       customer_date_birthday,
                       customer_gender
               FROM " . self::table_customer . "
               WHERE customer_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            //$intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryCustomerInfo);
            $intOk = $this->getArray($sql, $aryCustomerInfo, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCustomerCTV($aryConditions, &$aryCustomerCTV, $memberId = null) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_user_name,
                       customer_email,
                       customer_address,
                       customer_home_phone,
                       customer_mobile_phone,
                       customer_date_birthday,
                       customer_gender,
                       customer_join_date
               FROM " . self::table_customer . "
               WHERE customer_del_flag = ?
               AND customer_is_ctv = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            if (isset($memberId)) {
                $sql.= " AND customer_of_member_id = ?";
                $aryBin[] = $memberId;
            }
            $intOk = $this->getArray($sql, $aryCustomerCTV, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCustomerByKdId($aryConditions, &$aryCustomer) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_user_name,
                       customer_email,
                       customer_address,
                       customer_home_phone,
                       customer_mobile_phone,
                       customer_date_birthday,
                       customer_gender,
                       customer_join_date,
                       customer_yahoo,
                       customer_skype
               FROM " . self::table_customer . "
               WHERE customer_del_flag = ?
               AND customer_is_ctv = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            if (isset($aryConditions['customer_of_member_id'])) {
                $kdId = $aryConditions['customer_of_member_id'];
                $sql.=" AND customer_of_member_id = ?";
                $aryBin[] = $kdId;
            }

            if (isset($aryConditions['customer_id'])) {
                $ctvId = $aryConditions['customer_id'];
                $sql.=" AND customer_id = ?";
                $aryBin[] = $ctvId;
            }
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryCustomer, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCtvByMemberId($aryConditions, &$aryData, $memberId = null) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_email,
                       customer_address,
                       customer_home_phone,
                       customer_mobile_phone,
                       customer_date_birthday,
                       customer_gender,
                       customer_join_date,
                       customer_bank_name,
                       customer_bank_number,
                       customer_yahoo,
                       customer_skype
               FROM " . self::table_customer . "
               WHERE customer_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($memberId)) {
                $sql.=" AND customer_of_member_id = ?";
                $aryBin[] = $memberId;
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCustomerByListId($aryConditions, &$aryData, $listCusId = null) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name,
                       customer_email,
                       customer_address,
                       customer_home_phone,
                       customer_mobile_phone,
                       customer_date_birthday,
                       customer_gender,
                       customer_join_date,
                       customer_bank_name,
                       customer_bank_number,
                       customer_yahoo,
                       customer_skype,
                       customer_of_member_id
               FROM " . self::table_customer . "
               WHERE customer_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($listCusId)) {
                $sql.=" AND customer_id IN($listCusId)";
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductCustomer($aryProductData) {
        try {
            $intOk = $this->insert(self::table_customer_product, $aryProductData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerProductByCusId($aryConditions, &$aryCustomerProduct) {
        try {
            $custommerId = $aryConditions['customer_product_customer_id'];
            $monthProcess = $aryConditions['customer_product_month_process'];
            $yearProcess = $aryConditions['customer_product_year_process'];
            $sql = "SELECT customer_product_id,
                        customer_product_customer_id,
                        customer_product_product_name,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_date_process,
                        customer_product_kd_profit,
                        customer_product_status_finish,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_total_profit,
                        customer_product_is_tax,
                        customer_product_ctv_profit,
                        customer_product_total_price,
                        customer_product_transport,
                        customer_product_services,
                        customer_product_status_finish
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_customer_id = ?
                AND customer_product_month_process = ?
                AND customer_product_year_process = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $custommerId;
            $aryBin[] = $monthProcess;
            $aryBin[] = $yearProcess;
            $intOk = $this->getArray($sql, $aryCustomerProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getMyCustomerProductByCusId($aryConditions, &$aryCustomerProduct) {
        try {
            $custommerId = $aryConditions['customer_product_customer_id'];
            $kdId = $aryConditions['customer_product_kd_id'];
            $sql = "SELECT customer_product_id,
                        customer_product_customer_id,
                        customer_product_product_name,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_date_process,
                        customer_product_kd_profit,
                        customer_product_status_finish,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_total_profit,
                        customer_product_is_tax,
                        customer_product_ctv_profit,
                        customer_product_total_price,
                        customer_product_transport,
                        customer_product_services,
                        customer_product_status_finish
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_customer_id = ?
                AND customer_product_kd_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $custommerId;
            $aryBin[] = $kdId;
            $intOk = $this->getArray($sql, $aryCustomerProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCtvproductById($ctvProductId, &$aryCtvProduct) {
        try {
            $sql = "SELECT customer_product_id,
                        customer_product_customer_id,
                        customer_product_product_name,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_date_process,
                        customer_product_kd_profit,
                        customer_product_status_finish,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_total_profit,
                        customer_product_is_tax,
                        customer_product_ctv_profit,
                        customer_product_total_price,
                        customer_product_transport,
                        customer_product_services,
                        customer_product_disparity
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $ctvProductId;
            $intOk = $this->getArray($sql, $aryCtvProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCtvProductByKdId($memberId, &$aryCtvProduct) {
        try {
            $sql = "SELECT customer_product_customer_id,
                        customer_product_id,
                        customer_product_ctv_profit
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_kd_id = ?
                AND customer_product_status_finish = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $memberId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryCtvProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListCtvByProduct(&$aryCtvProduct, &$aryKd, $memberId = null, $ctvId = null) {
        try {
            $sql = "SELECT customer_product_customer_id
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($memberId) && $memberId != 0) {
                $sql.=" AND customer_product_kd_id = ?";
                $aryBin[] = $memberId;
            }
            if (isset($ctvId) && $ctvId != 0) {
                $sql.=" AND customer_product_customer_id = ?";
                $aryBin[] = $ctvId;
            }

            $intOk = $this->getArray($sql, $aryCtvProduct, $aryBin);

            $sql2 = "SELECT customer_product_kd_id FROM " . self::table_customer_product . "
                    WHERE customer_product_del_flag = ?";
            $aryBin2 = array();
            $aryBin2[] = 0;
            $this->getArray($sql2, $aryKd, $aryBin2);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getMemberKdByListId($strMemberKdId, &$aryMemberKd) {
        try {
            $sql = "SELECT member_id,
                        member_full_name,
                        member_login_name
                FROM " . self::table_member . "
                WHERE member_del_flag = ?
                AND member_id IN($strMemberKdId)";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryMemberKd, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerProductByMonth($aryConditions, &$aryProductCurrentMonth) {
        try {
            $sql = "SELECT customer_product_customer_id,
                        customer_product_id,
                        customer_product_ctv_profit,
                        customer_product_number,
                        customer_product_kd_profit,
                        customer_product_status_finish
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            if (isset($aryConditions['customer_product_kd_id']) && $aryConditions['customer_product_kd_id'] != 0) {
                $memberId = $aryConditions['customer_product_kd_id'];
                $sql.=" AND customer_product_kd_id = ?";
                $aryBin[] = $memberId;
            }
//        if(isset ($aryConditions['customer_product_customer_id'])){
//            $ctvId = $aryConditions['customer_product_customer_id'];
//            $sql.=" AND customer_product_customer_id = $ctvId";
//        }
            if (isset($aryConditions['customer_product_month_process']) && isset($aryConditions['customer_product_year_process'])) {
                $customer_product_month_process = $aryConditions['customer_product_month_process'];
                $customer_product_year_process = $aryConditions['customer_product_year_process'];
                $sql.=" AND customer_product_month_process = ?
                    AND customer_product_year_process = ?";
                $aryBin[] = $customer_product_month_process;
                $aryBin[] = $customer_product_year_process;
            }
            $intOk = $this->getArray($sql, $aryProductCurrentMonth, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateFinishStatus($aryCondition, $aryConfig) {
        try {
            $intOk = $this->update(self::table_customer_product, $aryCondition, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateCtvProduct($aryConfig, $aryUpdate) {
        try {
            $intOk = $this->update(self::table_customer_product, $aryUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkExistedCtvProduct($aryConditions, &$aryResultData) {
        try {
            $ctvId = $aryConditions['customer_product_customer_id'];
            $monthProcess = $aryConditions['customer_product_month_process'];
            $yearProcess = $aryConditions['customer_product_year_process'];
            $sql = "SELECT customer_statistics_id FROM " . self::table_customer_statistics . "
                WHERE customer_statistics_cus_id = ?
                AND customer_statistics_month = ?
                AND customer_statistics_year = ?";
            $aryBin = array();
            $aryBin[] = $ctvId;
            $aryBin[] = $monthProcess;
            $aryBin[] = $yearProcess;
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertStatisticsCtvProduct($aryData) {
        try {
            $intOk = $this->insert(self::table_customer_statistics, $aryData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getTotalCtvProductAndProfit(&$aryTotalProfit) {
        try {
            $sql = "SELECT customer_product_customer_id,
                        customer_product_id,
                        customer_product_ctv_profit,
                        customer_product_number,
                        customer_product_kd_profit,
                        customer_product_status_finish
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryTotalProfit, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerEmail($checkEmail, &$customer_Email) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name
                FROM " . self::table_customer . "
                    WHERE customer_email = ?";
            $aryBin = array();
            $aryBin[] = $checkEmail;
            $intOk = $this->getArray($sql, $customer_Email, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerUsername($username, &$customer_user_name) {
        try {
            $sql = "SELECT customer_id,
                       customer_full_name
                FROM " . self::table_customer . "
                    WHERE customer_user_name = ?";
            $aryBin = array();
            $aryBin[] = $username;
            $intOk = $this->getArray($sql, $customer_user_name, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveCustomerData($aryCustomer, &$customerId) {
        try {
            $intOk = $this->insert(self::table_customer, $aryCustomer);
            $customerId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchCustomerInfoData($aryConditions, &$aryCustomerData) {
        try {
            $sql = "SELECT customer_id,
                        customer_full_name,
                        customer_address,
                        customer_mobile_phone
                FROM " . self::table_customer . "
                WHERE customer_del_flag = ?
                AND customer_is_customer = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            if (isset($aryConditions['customer_full_name_search']) && strlen(trim($aryConditions['customer_full_name_search'])) > 0) {
                $sql.=" AND customer_full_name_search LIKE ?";
                $aryBin[] = "%" . $aryConditions['customer_full_name_search'] . "%";
            }
            if (isset($aryConditions['customer_mobile_phone_search']) && strlen(trim($aryConditions['customer_mobile_phone_search'])) > 0) {
                $sql.=" AND customer_mobile_phone LIKE ?";
                $aryBin = "%" . $aryConditions['customer_mobile_phone_search'] . "%";
            }
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryCustomerData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchMyProfitData($aryConditions, &$aryData) {
        try {
            $sql = "SELECT customer_product_id,
                        customer_product_product_name,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_total_profit,
                        customer_product_total_price,
                        customer_product_is_tax,
                        customer_product_date_process,
                        customer_product_customer_id
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_is_customer = ?";
            $kdId = $aryConditions['customer_product_kd_id'];
            $sql.=" AND customer_product_kd_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            $aryBin[] = $kdId;
            if (isset($aryConditions['customer_product_month_process'])) {
                $monthProcess = $aryConditions['customer_product_month_process'];
                $sql.=" AND customer_product_month_process = ?";
                $aryBin[] = $monthProcess;
            }
            if (isset($aryConditions['customer_product_year_process'])) {
                $yearProcess = $aryConditions['customer_product_year_process'];
                $sql.=" AND customer_product_year_process = ?";
                $aryBin[] = $yearProcess;
            }
            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCustomerProductById($productId, &$aryProductData) {
        try {
            $sql = "SELECT customer_product_id,
                        customer_product_customer_id,
                        customer_product_product_name,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_date_process,
                        customer_product_kd_profit,
                        customer_product_status_finish,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_total_profit,
                        customer_product_is_tax,
                        customer_product_ctv_profit,
                        customer_product_total_price,
                        customer_product_transport,
                        customer_product_services,
                        customer_product_disparity
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryProductData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateMyProduct($aryConfigProduct, $aryProduct) {
        try {
            $intOk = $this->update(self::table_customer_product, $aryProduct, $aryConfigProduct);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateMyCustomerInfo($aryConfigCustomer, $aryCustomerData) {
        try {
            $intOk = $this->update(self::table_customer, $aryCustomerData, $aryConfigCustomer);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getMyCustomerProduct($aryConditions, &$aryProductData) {
        try {
            $sql = "SELECT customer_product_id,
                        customer_product_product_name,
                        customer_product_number,
                        customer_product_unit,
                        customer_product_in_price,
                        customer_product_out_price,
                        customer_product_total_profit,
                        customer_product_total_price,
                        customer_product_is_tax,
                        customer_product_date_process,
                        customer_product_customer_id
                FROM " . self::table_customer_product . "
                WHERE customer_product_del_flag = ?
                AND customer_product_is_customer = ?";
            $kdId = $aryConditions['customer_product_kd_id'];
            $sql.=" AND customer_product_kd_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;
            $aryBin[] = $kdId;
            $intOk = $this->getArray($sql, $aryProductData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductCategory(&$aryProductCategory) {
        try {
            $sql = "SELECT  category_id,
                        category_name,
                        category_parent,
                        category_level,
                        category_name_filter,
                        category_total_child
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?
                    ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getRootProductCategory(&$aryRootCategory) {
        try {
            $sql = "SELECT  category_id,
                        category_name,
                        category_name_filter
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?
                    AND category_parent = ?
                    AND category_is_show = ?
                    ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 0;
            $aryBin[] = 1;
            $intOk = $this->getArray($sql, $aryRootCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductByListCatId($listCategoryId, $limit, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_maker_name,
                        product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_price_vnd_km,
                        product_price_active_km,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat,
                        product_type_id
                FROM " . self::table_product . "

                    WHERE product_del_flag = ? ";

            $sql.=" AND product_category_id IN($listCategoryId) AND product_price_vnd != 0";


            $sql.=" ORDER BY product_updated_date DESC, product_price_vnd DESC";

            $sql.=" LIMIT  $limit";

            $aryBin = array();
            $aryBin[] = 0;

            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductByType($productType, &$aryProduct, $listCategory = null) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_maker_name,
                        product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat
                FROM " . self::table_product . "

                    WHERE product_del_flag = ? ";

            $sql.=" AND product_type_id = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productType;

            if (isset($listCategory)) {
                $sql.=" AND product_category_id IN($listCategory)";
            }


            $sql.=" ORDER BY product_updated_date DESC";

            $sql.=" LIMIT 6";

            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryContent($categoryId, &$aryContent) {
        try {
            $sql = "SELECT  category_title_header,
                        category_keyword,
                        category_description,
                        category_content,
                        category_content_h1
                FROM " . self::table_product_category . "
                WHERE category_id = ? AND category_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $categoryId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryContent, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateCategoryContent($aryConfig, $aryData) {
        try {
            $intOk = $this->update(self::table_product_category, $aryData, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertCategoryContent($aryData) {
        try {
            $intOk = $this->insert(self::table_category_content, $aryData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getIntroductionData(&$aryIntroduction, $typeId = 0) {
        try {
            $sql = "SELECT mc_company_common_id,
                        mc_company_commom_link,
                        mc_company_common_title,
                        mc_company_common_title_filter,
                        mc_company_common_content_filter,
                        mc_company_common_create_date,
                        mc_company_common_update_date,
                        mc_company_common_creator_name,
                        mc_company_common_updator_name
                FROM " . self::table_company_common . "
                WHERE mc_company_common_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            if($typeId != 0){
                $sql.=" AND mc_company_commom_type = ? ";
                $aryBin[] = $typeId;
            }
            $intOk = $this->getArray($sql, $aryIntroduction, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getIntroductionDataById($introductionId, &$aryIntroduction) {
        try {
            $sql = "SELECT mc_company_common_id,
                        mc_company_common_title,
                        mc_company_commom_type,
                        mc_company_common_content
                FROM " . self::table_company_common . "
                    WHERE mc_company_common_id = ?";
            $aryBin = array();
            $aryBin[] = $introductionId;
            $intOk = $this->getArray($sql, $aryIntroduction, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateIntroduction($aryCondition, $aryIntroduction) {
        try {
            $intOk = $this->update(self::table_company_common, $aryIntroduction, $aryCondition);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertIntroductionData($aryData) {
        try {
            $intOk = $this->insert(self::table_company_common, $aryData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateParentFromCategory($aryParentFromCategoryUpdate, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_category, $aryParentFromCategoryUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateCategoryTotalChild($aryData, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_category, $aryData, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveSupportOnline($aryData) {
        try {
            $intOk = $this->insert(self::table_support_online, $aryData);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSupportOnlineData(&$aryData) {
        try {
            $sql = "SELECT support_online_id,
                        support_online_name,
                        support_online_yahoo,
                        support_online_skyper,
                        support_online_mobile
                        FROM " . self::table_support_online . "
            WHERE support_online_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateSupportOnline($aryConfig, $aryDelete) {
        try {
            $intOk = $this->update(self::table_support_online, $aryDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkProductOrderExist($productId, &$aryData) {
        try {
            $sql = "SELECT product_order_product_id,
                        product_order_total_product
                FROM " . self::table_product_order . "
                WHERE product_order_product_id = ? AND product_order_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $productId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductOrder($aryConfig, $aryUpdateData) {
        try {
            $intOk = $this->update(self::table_product_order, $aryUpdateData, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertCustomerProductOrder($aryData, &$productCustomerId) {
        try {
            $intOk = $this->insert(self::table_product_customer_order, $aryData);
            $productCustomerId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateStatusOrderActive($aryConfig, $aryData) {
        try {
            $intOk = $this->update(self::table_product_order, $aryData, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchCustomerOrderDetail($aryConditions, &$aryCustomer, $searchType) {
        try {
            $sql = "SELECT  order_detail_id,
                        order_detail_full_name,
                        order_detail_address,
                        order_detail_phone_number,
                        order_detail_email,
                        order_detail_yahoo,
                        order_detail_address_delivery,
                        order_detail_method_delivery,
                        order_detail_delivery_name,
                        order_detail_method_payment,
                        order_detail_payment_name,
                        order_detail_active,
                        order_detail_created_date,
                        order_detail_company_name,
                        order_detail_company_address,
                        order_detail_company_tax_code,
                        order_detail_is_process
                FROM " . self::table_product_order_detail . "
                    WHERE order_detail_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;

            if (is_numeric($aryConditions['order_detail_is_process'])) {
                $sql.=" AND order_detail_is_process = ? ";
                $aryBin[] = $aryConditions['order_detail_is_process'];
            }

            if (is_numeric($aryConditions['order_detail_created_date_month'])) {
                $sql.=" AND order_detail_created_date_month = ?";
                $aryBin[] = $aryConditions['order_detail_created_date_month'];
            }
            if (is_numeric($aryConditions['order_detail_created_date_year'])) {
                $sql.=" AND order_detail_created_date_year = ?";
                $aryBin[] = $aryConditions['order_detail_created_date_year'];
            }

            if (isset($aryConditions['order_detail_search_name'])) {
                $sql.=" AND order_detail_search_name LIKE ?";
                $aryBin[] = "%" . $aryConditions['order_detail_search_name'] . "%";
            }
            if (isset($aryConditions['order_detail_phone_number'])) {
                $sql.=" AND order_detail_phone_number LIKE ?";
                $aryBin[] = "%" . $aryConditions['order_detail_phone_number'] . "%";
            }
            if (isset($aryConditions['order_detail_email'])) {
                $sql.=" AND order_detail_email LIKE ?";
                $aryBin[] = "%" . $aryConditions['order_detail_email'] . "%";
            }

            if (isset($aryConditions['order'])) {
                $orderBy = $aryConditions['order'];
                $sql.=" ORDER BY order_detail_created_date $orderBy";
            }

            if (isset($searchType) && $searchType == 'export') {

                $intOk = $this->getArray($sql, $aryCustomer, $aryBin);
            } else {

                $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryCustomer, $aryBin);
            }
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertCustomerOrderInfo($aryCustomer, &$customerId) {
        try {
            $intOk = $this->insert(self::table_product_order_detail, $aryCustomer);
            $customerId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductOrder($aryProductOrder) {
        try {
            $intOk = $this->insert(self::table_product_order, $aryProductOrder);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getListContact(&$aryContact, $aryConditions) {
        try {
            $sql = "SELECT customer_contact_id,
                        customer_contact_title,
                        customer_contact_full_name,
                        customer_contact_email,
                        customer_contact_address,
                        customer_contact_mobile,
                        customer_contact_content,
                        customer_contact_content_filter,
                        customer_contact_send_date,
                        customer_contact_is_read
               FROM " . self::table_customer_contact . "
               WHERE customer_contact_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;

            if (isset($aryConditions['read_type']) && is_numeric($aryConditions['read_type'])) {
                $sql.=" AND customer_contact_is_read = ?";
                $aryBin[] = $aryConditions['read_type'];
            }
            $sql.=" ORDER BY customer_contact_send_date DESC";

            $intOk = $this->paging($sql, $aryConditions['curent_page'], $aryConditions['record_per_page'], $aryContact, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getContactDetail($contactId, &$aryContact) {
        try {
            $sql = "SELECT customer_contact_id,
                        customer_contact_title,
                        customer_contact_full_name,
                        customer_contact_email,
                        customer_contact_address,
                        customer_contact_mobile,
                        customer_contact_content,
                        customer_contact_content_filter,
                        customer_contact_send_date,
                        customer_contact_is_read
               FROM " . self::table_customer_contact . "
               WHERE customer_contact_del_flag = ?
               AND customer_contact_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $contactId;
            $intOk = $this->getArray($sql, $aryContact, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateContact($aryConfig, $aryUpdate) {
        try {
            $intOk = $this->update(self::table_customer_contact, $aryUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function userOnline() {
        try {
            $time = time();
            $time_check = $time - 300; //SET TIME 5 Minute

            $ip = $_SERVER['REMOTE_ADDR'];

            $sql = "SELECT ip FROM " . self::table_user_online . " WHERE ip = '$ip' ";

            $this->getArray($sql, $aryResultData);

            $count = count($aryResultData);

            if ($count == 0) {
                $aryData = array();
                $aryData['ip'] = $ip;
                $aryData['time'] = $time;
                $this->insert(self::table_user_online, $aryData);
                //update visited
                $sql = "UPDATE " . self::table_visited . " SET mc_visited = mc_visited + 1";
                $this->Excute($sql);
            } else {
                $sql = "UPDATE " . self::table_user_online . " SET time='$time' WHERE ip = '$ip'";
                $this->Excute($sql);
            }

            $sql = "SELECT ip FROM " . self::table_user_online;

            $this->getArray($sql, $aryOnline);

            $sql = "SELECT mc_visited FROM " . self::table_visited;

            $this->getArray($sql, $aryVisited);

            $aryResult = array();
            $aryResult['user_online'] = count($aryOnline);
            $aryResult['visited'] = $aryVisited[0]['mc_visited'];

            // if over 5 minute, delete session
            $sql = "DELETE FROM " . self::table_user_online . " WHERE time < $time_check";

            $this->Excute($sql);
            return $aryResult;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

}

?>
